﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}
<link href="~/lib/layui/2.7.6/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/2.7.6/layui.js"></script>
<style>
    .layui-form-item .layui-input-inline {
        height:10px;
    }
    .layui-input-block {
        margin-left: 5px !important; 
        min-height: 36px;
    }
    .layui-input{
        height: 28px !important;
        line-height: 0.8 !important;
        background-color: rgb(255, 255, 255);
        color: rgba(0, 0, 0, 0.85);
        border-width: 1px;
        border-style: solid;
        border-radius: 5px;
    }
</style>
<div class="wrapper animated fadeInRight">
    <form action="" class="layui-form fairy-form">
        <div class="layui-form" id="from">
            <div class="layui-bg-gray">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header">退货商品</div>
                            <div class="layui-card-body">
                                <table class="layui-table" id="goodsitems" lay-size="sm">
                                    <colgroup>
                                        <col width="150">
                                        <col width="150">
                                        <col width="200">
                                        <col>
                                        <col>
                                        <col>
                                    </colgroup>
                                    <thead>
                                        <tr>
                                            <th>商品图片</th>
                                            <th>商品名称</th>
                                            <th>价格/货物</th>
                                            <th>规格颜色</th>
                                            <th>车架号</th>
                                            <th>小计</th>
                                        </tr>
                                    </thead>
                                    <tbody id="goodsitem">
                                        @*<tr>
                                            <td style="text-align:center;"><img id="product_pic" src="" class="img-xs" /></td>
                                            <td style="text-align:center;"></td>
                                            <td style="text-align:center;"></td>
                                            <td style="text-align:center;"></td>
                                            <td style="text-align:center;"></td>
                                            <td style="text-align:center;"></td>
                                        </tr>*@
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td colspan="5" style="color:red;text-align:center;">合计</td>
                                            <td style="color:red;text-align:center;" id="product_real_price">0.00</td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-bg-gray">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header">服务单信息</div>
                            <div class="layui-card-body">
                                <table class="layui-table" lay-size="sm">
                                    <colgroup>
                                        <col width="40">
                                        <col width="150">
                                    </colgroup>
                                    <tbody>
                                        <tr>
                                            <td class="layui-bg-gray">申请状态</td>
                                            <td id="status"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">订单编号</td>
                                            <td id="ordersn"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">申请时间</td>
                                            <td id="createtime"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">联系人</td>
                                            <td id="user"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">联系电话</td>
                                            <td id="mobile"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">退货原因</td>
                                            <td id="refundType"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">问题描述</td>
                                            <td id="remark"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">凭证图片</td>
                                            <td id="proof_pics"></td>
                                        </tr>
                                    </tbody>
                                </table>

                                <table class="layui-table" lay-size="sm">
                                    <colgroup>
                                        <col width="40">
                                        <col width="150">
                                    </colgroup>
                                    <tbody>
                                        <tr>
                                            <td class="layui-bg-gray">订单金额</td>
                                            <td id="payment_money">
                                            </td>
                                        </tr>
                                        <tr id="divamount">
                                            <td class="layui-bg-gray">确认退款金额</td>
                                            <td>
                                                <div class="layui-input-block layui-input-inline" style="border-radius:10px">
                                                    <input type="text" id="amount" style="line-height:8px;" name="price_min" placeholder="￥" autocomplete="off" class="layui-input">
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">收货人姓名</td>
                                            <td id="name"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">所在区域</td>
                                            <td id="area"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">详细地址</td>
                                            <td id="detail_address"></td>
                                        </tr>
                                        <tr>
                                            <td class="layui-bg-gray">联系电话</td>
                                            <td id="phone"></td>
                                        </tr>
                                    </tbody>
                                </table>

                                <table class="layui-table" lay-size="sm">
                                    <colgroup>
                                        <col width="40">
                                        <col width="150">
                                    </colgroup>
                                    <tbody>
                                        <tr>
                                            <td class="layui-bg-gray">处理备注</td>
                                            <td>
                                                <div class="layui-input-block" style="border-radius:5px">
                                                    <textarea id="processnote" placeholder="请输入内容" class="layui-textarea"></textarea>
                                                </div>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="layui-form-item" id="TUIHUO">
            <div class="layui-input-block" style="text-align:center;">
                <button onclick="QueRenTuiHuo" class="layui-btn layui-btn-sm">确认退货</button>
                <button onclick="JuJueTuiHuo" class="layui-btn layui-btn-sm layui-btn-primary">拒绝退货</button>
            </div>
        </div>
        <div style="display:none" id="SHOUHUO" class="layui-form-item">
            <div class="layui-input-block" style="text-align:center;">
                <button onclick="QueRenShouHuo" class="layui-btn layui-btn-sm layui-btn-normal">确认收货</button>
                <button onclick="QueRenTuiHuo" class="layui-btn layui-btn-sm layui-btn-primary">直接退款</button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    layui.config({
    }).use(['form', 'table'], function () {
        var form = layui.form, skuTable = layui.skuTable;
    });
    $(function () {
        getForm();

        $('#form').validate({
            rules: {
                refundType: { required: true }
            }
        });
    });

    function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/QixingManage/OrderRefundApply/GetOrderRefundApplyFormJson")' + '?id=' + id,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        if (obj.Data.status==0) {
                            $("#TUIHUO").hide();
                            $("#SHOUHUO").show();
                        }
                        if (obj.Data.status==1) {
                            $("#TUIHUO").hide();
                            $("#SHOUHUO").show();
                        }
                        if (obj.Data.status==2)
                        {
                            $("#TUIHUO").hide();
                            $("#SHOUHUO").hide();
                        }
                        if (obj.Data.status ==3) {
                            $("#TUIHUO").hide();
                            $("#SHOUHUO").hide();
                        }

                        //$("#product_pic").attr('src', obj.Data.product_pic);
                        //$("#product_name").text(obj.Data.product_name);
                        //$("#product_price").text(obj.Data.product_price);
                        //$("#product_count").text(obj.Data.product_count);
                        //$("#product_real_price").text(obj.Data.product_real_price);
                        //$("#product_attr").text(obj.Data.product_attr);

                        // 遍历商品集合
                        $.each(obj.Data.itemsEntities, function (index, product) {
                            var row = "<tr>" +
                                "<td style='text-align:center;'><img src='" + product.image + "' class='img-xs' /></td>" +
                                "<td style='text-align:center;'>" + product.goods_name + "</td>" +
                                "<td style='text-align:center;'>" + product.refund_price.toFixed(2) + "</td>" +
                                "<td style='text-align:center;'>" + product.skuName + "</td>" +
                                "<td style='text-align:center;'>" + product.VIN + "</td>" +
                                "<td style='text-align:center;'></td>" +
                                "</tr>";

                            // 将行添加到表格中
                            $("#goodsitems tbody").append(row);

                            // 计算合计值
                            //totalPrice += product.price * product.quantity;
                        });


                        //$("#price").text(obj.Data.product_real_price * obj.Data.product_count);
                        switch (obj.Data.status) {
                            case 0:
                                $("#status").text("待处理");
                                break;
                            case 1:
                                $("#status").text("待处中");
                                break;
                            case 2:
                                $("#status").text("已完成");
                                break;
                            case 3:
                                $("#status").text("已拒绝");
                                break;
                            default:
                        }

                        $("#ordersn").text(obj.Data.ordersn);
                        $("#createtime").text(obj.Data.createtime);
                        $("#user").text(obj.Data.return_name);
                        $("#mobile").text(obj.Data.return_phone);

                        switch (obj.Data.refundType) {
                            case @refundType.A.ParseToInt():
                                $("#refundType").text("@refundType.A.GetDescription()");
                                break;
                             case @refundType.B.ParseToInt():
                                $("#refundType").text("@refundType.B.GetDescription()");
                                break;
                             case @refundType.C.ParseToInt():
                                $("#refundType").text("@refundType.C.GetDescription()");
                                break;
                             case @refundType.D.ParseToInt():
                                $("#refundType").text("7天无理由退货");
                                break;
                             case @refundType.E.ParseToInt():
                                $("#refundType").text("@refundType.E.GetDescription()");
                                break;
                             case @refundType.F.ParseToInt():
                                $("#refundType").text("@refundType.F.GetDescription()");
                                break;
                             case @refundType.G.ParseToInt():
                                $("#refundType").text("@refundType.G.GetDescription()");
                                break;
                            default:
                        }

                        $("#remark").text(obj.Data.remark);
                        var html = "";
                        if (obj.Data.proof_pics!=null)
                        {
                            var arrimages = obj.Data.proof_pics.split(",");
                            for (var i = 0; i <arrimages.length; i++) {
                                html += "<img class=\"img-xs\" src=" + arrimages[i]+"  />";
                            }
                            $("#proof_pics").html(html);
                        }

                        $("#payment_money").text(obj.Data.createtime);
                        $("#amount").val(obj.Data.amount);
                        $("#name").text(obj.Data.name);
                        $("#area").text(obj.Data.province + "-" + obj.Data.city + "-" + obj.Data.region);
                        $("#detail_address").text(obj.Data.detail_address);
                        $("#phone").text(obj.Data.phone);
                        $("#processnote").text(obj.Data.processnote);
                    }
                }
            });
        }
    }

    function JuJueTuiHuo()
    {
        var postData = { Id: id };
        postData.status =3;
        postData.processnote = $("#processnote").val();
         ys.ajax({
                url: '@Url.Content("~/QixingManage/OrderRefundApply/SaveOrderRefundApplyFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
         });
    }

    function QueRenTuiHuo()
    {
        var postData = { Id: id };
        postData.status = 2;
        postData.amount = $("#amount").val();
        postData.processnote = $("#processnote").val();
         ys.ajax({
                url: '@Url.Content("~/QixingManage/OrderRefundApply/SaveOrderRefundApplyFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
    }

    function QueRenShouHuo()
    {
        var postData = { Id: id };
        postData.status = 1;
         ys.ajax({
                url: '@Url.Content("~/QixingManage/OrderMaster/SaveOrderRefundApplyFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
    }
</script>

